package com.hanock.sm.fork2d;

public class AlphaTransform extends Transform {

	private float alphaFrom;
	private float alphaTo;
	private int timeFrom;
	private int timeTo;
	private boolean finished;
	
	
	public AlphaTransform(float alphaFrom, float alphaTo, int timeFrom, int timeTo) {
		
		this.alphaFrom = alphaFrom;
		this.alphaTo = alphaTo;
		this.timeFrom = timeFrom;
		this.timeTo = timeTo;
	}
	
	@Override
	public void progress(Node node, int time) {
		super.progress(node, time);
		
		int act = getActionTime() - timeFrom;
		int interval = timeTo - timeFrom;
		
		if (act < 0)
			return;
		if (act > interval){
			if (!finished){
				finished = true;
				node.setAlpha(alphaTo);
			}
		}
		
		float a = alphaFrom + (alphaTo - alphaFrom)*1f*act/interval;
		node.setAlpha(a);
	}
	
	@Override
	public boolean isFinished() {
		return finished;
	}

}


















